package com.ssy.lingxi.product.repository.platform;

import com.ssy.lingxi.product.entity.platform.ProductCategoryAttribute;
import com.ssy.lingxi.product.entity.platform.ProductCategoryAttributePK;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author xiaomai
 * @Description 品类属性中间表Repository
 * @Date 2022/2/28 16:10
 **/
@Repository
public interface ProductCategoryAttributeRepository extends JpaRepository<ProductCategoryAttribute, ProductCategoryAttributePK>, JpaSpecificationExecutor<ProductCategoryAttribute> {


    /**
     * 根据品类Id查询所有中间表数据
     *
     * @param categoryId
     * @return
     */
    List<ProductCategoryAttribute> findAllByCategoryId(Integer categoryId);


    /**
     * 保存数据
     * @param categoryId
     * @param attributeId
     * @param sort
     */
    @Modifying
    @Query(value = "update product_category_attribute  set sort = :sort where category_id = :categoryId and attribute_id = :attributeId",nativeQuery = true)
    void updateData(@Param("categoryId")Integer categoryId, @Param("attributeId") Integer attributeId, @Param("sort") Integer sort);


}
